package com.tsvetanv.data.binding.string;

import junit.framework.TestCase;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.tsvetanv.data.binding.model.nested.Name;

public class CommandBeanBindingTest extends TestCase {

	private Name name;
	private ServletRequestDataBinder binder;
	private MockHttpServletRequest request;

	@Override
	protected void setUp() throws Exception {
		name = new Name();
		binder = new ServletRequestDataBinder(name, "nameBean");
		request = new MockHttpServletRequest();
	}

	public void testSimpleBind() {
		// just like /servlet?firstName=Tsvetan&lastName=Vasilev
		request.addParameter("firstName", "Tsvetan");
		request.addParameter("lastName", "Vasilev");

		// bind the request with the JavaBean "name"
		binder.bind(request);

		assertEquals("Tsvetan", name.getFirstName());
		assertEquals("Vasilev", name.getLastName());
	}
}
